package com.example.md.mddemo.hutooltest;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.example.md.mddemo.common.MyDateUtils;
import org.junit.Test;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * Copyright © 2018年 ziniuxiaozhu. All rights reserved.
 *
 * @Author 临江仙 hzqiuxm@163.com
 * TODO:亲爱的临江仙，请写点注释吧...........
 * @Date 2018/9/19 14:22
 */
public class Datetest {

    @Test
    public void test001() {

        Date date = new Date();
        String str1 = "2018-09-09";
        System.out.println(date);

        System.out.println(getYYYMMDDDateString(date));
        System.out.println(getYYYMMDDDate(str1));


        String dateStr = "2018-09-20";

        Date dateTime = cn.hutool.core.date.DateUtil.parse(dateStr);
        System.out.println("dateTime = " +dateTime);


    }

    @Test
    public void test002(){

        String simpleUUID = IdUtil.simpleUUID();
        System.out.println("simpleUUID = " + simpleUUID);

        String objectId = IdUtil.objectId();
        System.out.println("objectId = " + objectId);

        Snowflake snowflake = IdUtil.createSnowflake(1, 1);
        System.out.println("snowflake = " + snowflake.nextId());
    }


    public static String getYYYMMDDDateString(Date date) {
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        DateTimeFormatter sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        return sdf.format(MyDateUtils.DateToLocaleDate(date));
    }


    public static Date getYYYMMDDDate(String date) {
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        DateTimeFormatter sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd");

        try {
            return MyDateUtils.LocalDateToDate(LocalDate.parse(date,sdf));
        } catch (Exception e) {
        }
        return null;
    }
}
